package com.zhs.smartmall.member.service.impl;


import com.zhs.smartmall.member.model.UmsGrowthChangeHistory;
import com.zhs.smartmall.member.dao.UmsGrowthChangeHistoryDao;
import com.zhs.smartmall.member.service.IUmsGrowthChangeHistoryService;
import com.zhs.smartmall.member.dto.UmsGrowthChangeHistoryDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class UmsGrowthChangeHistoryServiceImpl extends ServiceImpl< UmsGrowthChangeHistoryDao, UmsGrowthChangeHistory> implements IUmsGrowthChangeHistoryService {

    @Resource
    private UmsGrowthChangeHistoryDao umsGrowthChangeHistoryDao;

    @Override
    @Transactional
    public R addOrUpdate(UmsGrowthChangeHistoryDto umsGrowthChangeHistoryDto) {
        if (BeanUtil.isEmpty(umsGrowthChangeHistoryDto)) throw new ServiceException("数据不能为空");
        UmsGrowthChangeHistory umsGrowthChangeHistory = new UmsGrowthChangeHistory();
        BeanUtil.copyProperties(umsGrowthChangeHistoryDto,umsGrowthChangeHistory);
        if (umsGrowthChangeHistoryDto.getId() == null){
            umsGrowthChangeHistoryDao.insert(umsGrowthChangeHistory);
            return R.ok("数据插入成功");
        }else {
            umsGrowthChangeHistoryDao.updateById(umsGrowthChangeHistory);
            return R.ok("数据更新成功");
        }
    }
}